package com.gamatechno.solodestination.model;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class AppPreferences {
	public static final String KEY_PREFS_SMS_BODY = "sms_body";
	public static final String KEY_PREFS_LAST_UPDATE = "lastupdate";
	public static final String KEY_PREFS_BAHASA = "bahasa";
	public static final String KEY_PREFS_IS_PERTAMA = "is_pertama";
	public static final String KEY_PREFS_ID_FB = "id_fb";
	
	private static final String APP_SHARED_PREFS = AppPreferences.class
			.getSimpleName(); // Name of the file -.xml
	private SharedPreferences _sharedPrefs;
	private Editor _prefsEditor;

	public AppPreferences(Context context) {
		this._sharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS,
				Activity.MODE_PRIVATE);
		this._prefsEditor = _sharedPrefs.edit();
	}

	public String getSmsBody() {
		return _sharedPrefs.getString(KEY_PREFS_SMS_BODY, "");
	}
	
	public String getLastUpdateStock() {
		return _sharedPrefs.getString(KEY_PREFS_LAST_UPDATE, "");
	}
	
	public void setLastUpdateStock() {
		Calendar cal = Calendar.getInstance(); 
		SimpleDateFormat sdf = new SimpleDateFormat("y/M/d HH:mm:ss");
		String datetimeNow = sdf.format(cal.getTime());
		_prefsEditor.putString(KEY_PREFS_LAST_UPDATE, datetimeNow);

		_prefsEditor.commit();
	}
	
	public String getBahasa() {
		return _sharedPrefs.getString(KEY_PREFS_BAHASA, "id");
	}
	
	public void setBahasa(String text) {

		_prefsEditor.putString(KEY_PREFS_BAHASA, text);

		_prefsEditor.commit();
	}
	
	public String getIdFb() {
		return _sharedPrefs.getString(KEY_PREFS_ID_FB, "");
	}
	
	public void setIdFb(String text) {

		_prefsEditor.putString(KEY_PREFS_ID_FB, text);

		_prefsEditor.commit();
	}
	
	public Boolean getIsPertama() {
		return _sharedPrefs.getBoolean(KEY_PREFS_IS_PERTAMA,true);
	}
	
	public void setIsPertama() {

		_prefsEditor.putBoolean(KEY_PREFS_IS_PERTAMA, false);

		_prefsEditor.commit();
	}

	public void saveSmsBody(String text) {
		_prefsEditor.putString(KEY_PREFS_SMS_BODY, text);
		_prefsEditor.commit();
	}
}
